package cn.wolfcode.cms.service.impl;

import cn.wolfcode.cms.domain.Exchange;
import cn.wolfcode.cms.mapper.ExchangeMapper;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IExchangeService;
import cn.wolfcode.cms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExchangeServiceImpl implements IExchangeService {

    @Autowired
    private ExchangeMapper exchangeMapper;

    public void save(Exchange entity) {
        exchangeMapper.insert(entity);

    }

    public void update(Exchange entity) {
        exchangeMapper.updateByPrimaryKey(entity);
    }

    public void delete(Long id) {
        exchangeMapper.deleteByPrimaryKey(id);
    }

    public Exchange get(Long id) {
        return exchangeMapper.selectByPrimaryKey(id);
    }

    public List<Exchange> list() {
        return exchangeMapper.selectAll();
    }

    public Object query(QueryObject qo) {
        //查总数
        int total = exchangeMapper.queryForCount(qo);
        if(total == 0){
            return new PageResult();
        }
        //查数据
        List<Exchange> rows = exchangeMapper.queryForList(qo);
        return new PageResult(total, rows);
    }

    public void updataBalance(Long mid, Integer balance) {
        exchangeMapper.updataBalance(mid,balance);
    }
}
